<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<script src="https://cdn.bootcdn.net/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
</head>

<body>
	<script>
		// browser
		const log = console.log;
		window.onload = function () {
			const socket = io.connect('http://127.0.0.1:7003')

			socket.on('connect', () => {
				const id = socket.id;
				log('#connect,', id, socket);
				// 监听自身 id 以实现 p2p 通讯
				socket.on(id, msg => {
					log('#receive,', msg);
				});
			});
			// 接收在线用户信息
			socket.on('online', msg => {
				log('#online,', msg);
			});
			socket.on('String',)
			// 系统事件
			socket.on('disconnect', msg => {

				log('#disconnect', msg);
			});

			socket.on('disconnecting', () => {
				log('#disconnecting');
			});

			socket.on('error', () => {
				log('#error');
			});

			window.socket = socket;
		}
	</script>
</body>

</html>